home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: help with queue
- Date: 19 Apr 1996 15:01:32 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4l89sc$kf6@sparcserver.lrz-muenchen.de>
- References: <4l73q1$148@itsop2.its.brooklyn.cuny.edu>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- dzielins@its.brooklyn.cuny.edu (Daniel Zielinski) writes:
-
- >Could anybody help me with QUEUE structure? It's node based.
- >It seems that assert function fails (It's in the removeQueue function)
- >Whenever I try to remove something from a QUEUE I get:
- > line 31 in QUEUE.c assert failed.
- >Any clues on what I'm doing wrong would be apriciated.
-
- >this is QUEUE.c
-
- >#include "QUEUE.h"
- >#include <assert.h>
- >#include <stdio.h>
-
- [insertQueue edited]
-
- >int
- >emptyQueue(Queue q) {
- > assert((q.front==NULL && q.rear==NULL) || (q.front!=NULL &&
- > q.rear!=NULL));
- > return q.front==NULL;
- >}
-
- This function obviously checks whether a queue is empty or not. It
- returns 1 if the queue is empty, 0 if it is not empty.
-
- >DataType
- >removeQueue(Queue *qp) {
- > Node *np;
- > DataType d;
-
- > assert(!emptyQueue(*qp)); <-------- THIS IS THE LINE
-
- The implementor of your queues states that his removeQueue() function
- is not able to remove something from an empty queue. Since (s)he
- wants to return the value of the removed node, this is a sane
- assumption.
-
- > np=qp->front;
- > d=np->data;
- > qp->front=np->next;
- > if (qp->front==NULL)
- > qp->rear=NULL;
- > deleteNode(np);
- > return d;
- >}
-
- >void
- >initQueue(Queue *qp) {
- > qp->front=qp->rear=NULL;
- >}
-
- This creates an empty queue. Your implementation of a queue assumes
- that only queues that are not empty can be passed to removeQueue().
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-